<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">

		<f:event type="preRenderView"
			listener="#{recruiterController.beforeSearch}" />

		<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		BUSCAR RECLUTADORES
		</h:panelGrid>

		</div>

		<h:form id="formSearch">
			<h:panelGrid style="margin:auto;">
				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages"></p:messages>
				</h:panelGrid>


				<h:panelGrid columns="6">
					<p:outputLabel value="Area"></p:outputLabel>
					<p:selectOneMenu id="areas" required="true"
						requiredMessage="Debe seleccionar area"
						value="#{recruiterController.areaSelected}">
						<f:selectItem itemValue="" itemLabel="Seleccione..."></f:selectItem>
						<f:selectItem itemValue="t" itemLabel="Todos"></f:selectItem>
						<f:selectItem itemValue="s" itemLabel="Sin Area"></f:selectItem>
						<f:selectItems value="#{recruiterController.areas}"></f:selectItems>
					</p:selectOneMenu>

					<p:outputLabel value="DNI"></p:outputLabel>
					<p:inputText style="width: 120px;"
						value="#{recruiterController.documentNumberSearch}"></p:inputText>

					<p:outputLabel value="Nombres"></p:outputLabel>
					<p:inputText style="width: 230px;"
						value="#{recruiterController.nameSearch}"></p:inputText>

				</h:panelGrid>
				<h:panelGrid style="margin:auto;text-align:center;">
					<p:commandButton icon="ui-icon-search"
						actionListener="#{recruiterController.search}"
						value="Buscar" process="@form"
						update=":formSearch:searchTable :formSearch:messages :formSearch:recruiterId :formSearch:editButtom">
					</p:commandButton>
				</h:panelGrid>
			</h:panelGrid>
			
			<h:panelGrid columns="3">
				<p:commandButton icon="ui-icon-plus" value="Agregar"
					action="add_recruiter.xhtml">
				</p:commandButton>

				<p:commandButton id="editButtom" action="edit_recruiter.xhtml"
					icon="ui-icon-pencil" value="Editar"
					disabled="#{recruiterController.recruiterSelected==null}">
					<f:param name="recruiterId"
						value="#{recruiterController.recruiterSelected.id}"></f:param>
				</p:commandButton>
				<p:outputLabel id="recruiterId"
					value="Reclutador seleccionado: #{recruiterController.recruiterSelected!=null?recruiterController.recruiterSelected.id:''}">
				</p:outputLabel>
			</h:panelGrid>


			<p:dataTable value="#{recruiterController.recruiters}" var="r"
				rowKey="#{r.id}" paginator="true" rows="10" id="searchTable"
				selectionMode="single" selection="#{recruiterController.recruiterSelected}">
				
				<p:ajax event="rowSelect"
					update=":formSearch:recruiterId :formSearch:editButtom" />
				<p:ajax event="rowUnselect"
					update=":formSearch:recruiterId :formSearch:editButtom" />

				<p:column headerText="ID" sortBy="#{r.id}">
					<h:outputText value="#{r.id}"></h:outputText>
				</p:column>
				
				<p:column headerText="DNI" sortBy="#{r.documentNumber}">
					<h:outputText value="#{r.documentNumber}"></h:outputText>
				</p:column>

				<p:column headerText="NOMBRES" sortBy="#{r.firstname}">
					<h:outputText value="#{r.firstname}"></h:outputText>
				</p:column>

				<p:column headerText="APELLIDOS" sortBy="#{r.lastname}">
					<h:outputText value="#{r.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="AREAS" sortBy="#{r.areasList}">
					<h:outputText value="#{r.areasList}"></h:outputText>
				</p:column>

			</p:dataTable>


		</h:form>
	</ui:define>

</ui:composition>
</html>
